import java.util.Scanner;

public class Ex4_29{
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		System.out.print("Enter a year and the week day for January 1: ");
		int year = input.nextInt();
		int weekDay = input.nextInt();
		for (int month = 1; month <= 12; month++){
			String monthStr = "";
			int days = 0;
			switch (month)
			{
			case 1: 
				monthStr = "January";
				days = 31;
				break;
			case 2:
				monthStr = "Febrary";
				if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
					days = 29;
				else
					days = 28;
				break;
			case 3:
				monthStr = "March";
				days = 31;
				break;
			case 4:
				monthStr = "April";
				days = 30;
				break;
			case 5:
				monthStr = "May";
				days = 31;
				break;
			case 6:
				monthStr = "June";
				days = 30;
				break;
			case 7:
				monthStr = "July";
				days = 31;
				break;
			case 8:
				monthStr = "Autumn";
				days = 31;
				break;
			case 9:
				monthStr = "September";
				days = 30;
				break;
			case 10:
				monthStr = "October";
				days = 31;
				break;
			case 11:
				monthStr = "November";
				days = 30;
				break;
			case 12:
				monthStr = "December";
				days = 31;
				break;
			}
			System.out.printf("\t\t%s %d\n", monthStr, year);
			System.out.printf("----------------------------------------\n");
			System.out.printf("%-6s%-6s%-6s%-6s%-6s%-6s%-6s\n", 
				"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
			for (int day = 0; day < weekDay; day++)
				System.out.printf("%-6c", ' ');
			for (int day = 1; day <= days; day++){
				System.out.printf(" %-5d", day);
				weekDay = (weekDay + 1) % 7;
				if (weekDay == 0)
					System.out.printf("\n");
			}
			System.out.printf("\n\n");
		}
	}
}